package org.come.Jpanel;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.tool.time.Limit;
import com.tool.time.TimeLimit;
import com.tool.time.TimerUtil;
import com.updateNew.MyIsif;

import org.come.Frame.ZhuFrame;
import org.come.bean.PayvipBean;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.CutButtonImage;
import org.come.until.FormsManagement;

import com.tool.btn.VipShopBtn;
import com.tool.tcpimg.UIUtils;
import org.come.until.MessagrFlagUntil;

/**
 * HGC-2019-11-21 VIP商品面板
 * 
 * @author Administrator
 * 
 */
public class VipGoodsJpanel extends JPanel {

	/**
	 * 领取按钮
	 */
	private VipShopBtn vipShopBtn;
	/**
	 * VIP阶段名称name<br>
	 * 
	 * 
	 */
	private String name = "V1会员奖励";
//	/** 描述 */
//	private RichLabel richLabel;
	/**
	 * 当前展示的物品
	 */
	private PayvipBean payvipBean;
	private JLabel jLabel;
	private Mlistener mlistener ;
	public VipGoodsJpanel() {
		setPreferredSize(new Dimension(136, 190));
		setOpaque(false);
		setLayout(null);

		getVipShopBtn();
//		getRichLabel();
		mlistener= new Mlistener(payvipBean);
		this.addMouseListener(mlistener);
	}


	/**
	 * 展示物品
	 * 
	 * @param payvipBean
	 */
	public void showGoods(PayvipBean payvipBean) {
		this.payvipBean = payvipBean;
		if (payvipBean != null) {
			mlistener.setPayvipBean(payvipBean);
//			richLabel.setText("#K" + payvipBean.getInstructiontext());
			getIconVip().setImage(CutButtonImage.getImage("img/item/S" + (19 + payvipBean.getGrade()) + ".png", -1, -1).getImage());
			getIconGift().setImage(CutButtonImage.getImage("img/item/S" + (9 + payvipBean.getGrade()) + ".png", -1, -1).getImage());

			name = "V" + payvipBean.getGrade() + "会员奖励";
		} else {
			vipShopBtn.setBtn(0);
		}
	}

	/**
	 * 兑换对应物品
	 */
	public void exchangeGoods() {
		String sendmes = Agreement.getAgreement().VipgradesureAgreement("v" + payvipBean.getGrade());
		SendMessageUntil.toServer(sendmes);
	}

	/**
	 * 移入移出
	 * 
	 * @author Administrator
	 * 
	 */
	class Mlistener implements MouseListener {
		
		private PayvipBean payvipBean;
		

		public Mlistener(PayvipBean payvipBean) {
			this.payvipBean = payvipBean;
		}

		@Override
		public void mouseClicked(MouseEvent e) {
			// TODO Auto-generated method stub

		}

		@Override
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub

		}

		@Override
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub

		}

		@Override
		public void mouseEntered(MouseEvent e) {
			if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE1)) {
				MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
			}
			if(payvipBean == null) {
                return;
            }
			ZhuFrame.getZhuJpanel().creatgoodtext(payvipBean);
		}

		@Override
		public void mouseExited(MouseEvent e) {
			if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE12)) {
				MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
			}
			// TODO Auto-generated method stub
			FormsManagement.HideForm(24);
		}

		public PayvipBean getPayvipBean() {
			return payvipBean;
		}

		public void setPayvipBean(PayvipBean payvipBean) {
			this.payvipBean = payvipBean;
		}
		

	}

	private ImageIcon iconBack;

	private ImageIcon iconGift, iconVip;

	@Override
	protected void paintComponent(Graphics g) {
		// TODO Auto-generated method stub
		super.paintComponent(g);
			if (payvipBean != null) {
				if (iconBack == null) {
					iconBack = CutButtonImage.getImage("inkImg/old/background/S3﻿.png", -1, -1);
				}
				g.drawImage(iconBack.getImage(), 0, 0, 136, 134, this);
				if (iconGift == null) {
					iconGift = CutButtonImage.getImage("img/item/S13.png", -1, -1);
				}
				g.drawImage(iconGift.getImage(), 20, 20, 100, 100, this);
				if (iconVip == null) {
					iconVip = CutButtonImage.getImage("img/item/S23.png", -1, -1);
				}
				g.drawImage(iconVip.getImage(), 10, 10, 30, 25, this);

				if (name != null) {
					g.setFont(UIUtils.TEXT_HY19);
					g.drawString(name, 10, 150);
				}
			}
	}

	public VipShopBtn getVipShopBtn() {
		if (vipShopBtn == null) {
			vipShopBtn = new VipShopBtn("inkImg/hongmu/1/lingqu.png", 1, 1, this);
			vipShopBtn.setBounds(38, 160, 69, 26);
			this.add(vipShopBtn);
		}
		return vipShopBtn;
	}

	public void setVipShopBtn(VipShopBtn vipShopBtn) {
		this.vipShopBtn = vipShopBtn;
	}

	public ImageIcon getIconBack() {
		return iconBack;
	}

	public void setIconBack(ImageIcon iconBack) {
		this.iconBack = iconBack;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}


	public ImageIcon getIconGift() {
		if (iconGift == null) {
			iconGift = new ImageIcon();
		}
		return iconGift;
	}

	public void setIconGift(ImageIcon iconGift) {
		this.iconGift = iconGift;
	}

	public ImageIcon getIconVip() {
		if (iconVip == null) {
			iconVip = new ImageIcon();
		}
		return iconVip;
	}

	public void setIconVip(ImageIcon iconVip) {
		this.iconVip = iconVip;
	}

	public PayvipBean getPayvipBean() {
		return payvipBean;
	}

	public void setPayvipBean(PayvipBean payvipBean) {
		this.payvipBean = payvipBean;
	}

	public Mlistener getMlistener() {
		return mlistener;
	}

	public void setMlistener(Mlistener mlistener) {
		this.mlistener = mlistener;
	}

}
